<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true"
    CodeFile="ViewBranches.aspx.cs" Inherits="ViewBranches" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
   
    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        window.onload = function() {
            TotalChkBx = parseInt('<%= this.gvBranches.Rows.Count %>');
            Counter = 0;
        }

        function SelectAll(CheckBox) {
            var TargetBaseControl = document.getElementById('<%= this.gvBranches.ClientID %>');
            var TargetChildControl = "chkselect";
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            var HeaderCheckBox = document.getElementById(HCheckBox);
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }         
    
    </script>
    <table width="100%">
        <tr>
            <td valign="middle" class="header">
                View Branches
            </td>
        </tr>
    </table>
    <asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    <br />
    <asp:GridView ID="gvBranches" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="PinCode" DataSourceID="ObjectDataSourceBranches" 
        HeaderStyle-CssClass="smallheader" HeaderStyle-BackColor="#a9c0f2" 
        BorderColor="#556CB0" GridLines="Vertical" Width="100%"  
        AllowPaging="True">
        <Columns>
            <asp:BoundField DataField="PinCode" HeaderText="Pin Code" ReadOnly="True" SortExpression="PinCode" />
            <asp:BoundField DataField="BranchName" HeaderText="Branch Name" SortExpression="BranchName" />
            <asp:BoundField DataField="BranchAddress" HeaderText="Address" SortExpression="BranchAddress" />
            <asp:BoundField DataField="BranchPhone" HeaderText="Phone" SortExpression="BranchPhone" />
            <asp:BoundField DataField="BranchFax" HeaderText="Fax" SortExpression="BranchFax" />
            <asp:BoundField DataField="CityID" HeaderText="City ID" SortExpression="CityID" />
            <asp:HyperLinkField DataNavigateUrlFields="PinCode" DataNavigateUrlFormatString="~/Pages_Admin/ManageBranches/EditBranch.aspx?PinCode={0}"
                HeaderText="Edit" Text="Edit" />
             <asp:TemplateField>
                <HeaderTemplate>
                    <asp:CheckBox ID="chkheader" runat="server" onclick="javascript:SelectAll(this);" />
                </HeaderTemplate>
                <ItemTemplate>
                    <div align="center">
                        <asp:CheckBox ID="chkselect" runat="server" ToolTip='<%# Eval("PinCode") %>' />
                    </div>
                </ItemTemplate>
                <ItemStyle Width="20px"></ItemStyle>
            </asp:TemplateField>
        </Columns>
        <HeaderStyle HorizontalAlign="Center" BackColor="#A9C0F2" CssClass="smallheader" />
        <AlternatingRowStyle BackColor="Gainsboro" />
        <RowStyle HorizontalAlign="Center" />
    </asp:GridView>
    <br />
    <asp:ObjectDataSource ID="ObjectDataSourceBranches" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="ListBranch" 
        TypeName="DALBranch"></asp:ObjectDataSource>
<div align="left">
     <asp:Button ID="btnAddBranch" runat="server" Text="Add new branch" 
         onclick="btnAddBranch_Click"  />
    <asp:Button ID="btnDeleteBranch" runat="server" Text="Delete selected branch" 
         onclick="btnDeleteBranch_Click" 
         onclientclick="return confirm(&quot;Are you sure you want to delete selected branch?&quot;);" />
    </div>
</asp:Content>
